package site.marqstree.kotlin.library.base.ui.activity

import android.os.Bundle
import site.marqstree.kotlin.library.base.common.BaseApplication
import site.marqstree.kotlin.library.base.injection.activity.ActivityComponent
import site.marqstree.kotlin.library.base.injection.activity.ActivityModule
import site.marqstree.kotlin.library.base.injection.activity.DaggerActivityComponent
import site.marqstree.kotlin.library.base.presenter.view.BasePresenter
import site.marqstree.kotlin.library.base.presenter.view.BaseView
import javax.inject.Inject


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.baselibrary.ui.activity
 * 文件名: BaseMvpActivity
 * 创建者: marqstree
 * 创建时间: 2020/2/17 14:31
 * 描述: TODO
 */
abstract open class BaseMvpActivity<T: BasePresenter<*>>: BaseActivity(), BaseView {

    @Inject
    lateinit var mPresenter: T

    lateinit var activityComponent: ActivityComponent

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //初始化Dagger的Activity层Component
        initActivityInjection()
        //初始化Dagger注册业务层Component
        initBusinessInjection()
    }

    //生成activity级依赖工厂管理者
    private fun initActivityInjection() {
        activityComponent = DaggerActivityComponent.builder()
            //传入activity级依赖工厂管理者依赖的app级依赖工厂管理者
            .appComponent((application as BaseApplication).appComponent)
            .activityModule(
                ActivityModule(
                    this
                )
            )
            .build()
    }

    /*
    Dagger注册业务层Component
    */
    protected abstract fun initBusinessInjection()

}